package Logic;

import java.text.DecimalFormat;

import utils.GamerException;
import utils.IniFile;
import utils.Vec;

public class GamerParams {

	
	public static final double version = 0.92;
	
	static public boolean isRendering = false;
    static public String[] yesno = {"no","yes"};
    static public double[] yesnoVals = {0,1};

    static public String[] detailLevel = {"low","medium", "high", "super high"};
    static public double[] detailLevelVals = {0.02,0.005, 0.0025, 0.001};


    
	
    public Vec convolve = new Vec(0,0,0);
    
	public Vec imageSize = new Vec(32,0,0);
	public Vec noStars = new Vec(0,0,0);
	public Vec starsSpread = new Vec(0,0,0);
	public Vec processors = new Vec(8,0,0);

	public Vec color = new Vec(1,1,1);
	public Vec power = new Vec(0.5,0,0);
	public Vec cutoff = new Vec(0.5,0,0);
	
	public Vec userColors = new Vec(0,0,0);

	public Vec noise = new Vec(0,0,0);

	static public DecimalFormat decimal = new DecimalFormat("0.0000##");
	static public DecimalFormat integer = new DecimalFormat("0.##");

	public Vec preview = new Vec(1,0,0);

	
	public Vec wavelengths = new Vec(3500,5000, 9000);
	
	public String mpiCommand = "/usr/local/bin/mpirun";

	public String galaxyFile = "SB0.gax";
	public String galaxyDir = "galaxies/";
	public String spectraDir = "spectra/";
	public String movieDir = "movie/";
	public String sceneDir = "scenes/";
	public String renderList = "gamer_scene.rl";
	
	
	
	public Vec screenSize = new Vec(1100,1000,0);
	
	public String settingsFile = "gamer.ini";
	
	
	public Vec renderlistCount = new Vec(100,0,0);
	public Vec renderlistSize = new Vec(100,0,0);
	
	
	public void Load() {
		try {
			IniFile ini = new IniFile(settingsFile);
			imageSize.x = ini.getDouble("image_size");
			processors.x = ini.getDouble("processors");
			color = ini.getVec("color");
			power.x = ini.getDouble("power");
			cutoff.x = ini.getDouble("cutoff");
			
			userColors.x = ini.getDouble("use_colors");
			wavelengths = ini.getVec("wavelengths");
			mpiCommand = ini.getString("mpirun_file");
			galaxyFile = ini.getString("default_galaxy");
			galaxyDir = ini.getString("default_galaxy_directory");

			convolve.x = ini.getDouble("convolve") / 100.0;
			noise = ini.getVec("noise");
			renderList = ini.getString("renderlist");
			preview.x = ini.getDouble("preview");
			noStars.x = ini.getDouble("no_stars");
			starsSpread.x = ini.getDouble("stars_spread");
			
		}
		catch (GamerException ge) {
			System.out.println("Error loading ini: " + ge.error);
		}
	}

	public void Save() {
		IniFile ini = new IniFile();
		ini.addKey("image_size", (int)imageSize.x);
		ini.addKey("processors", processors.x);
		ini.addKey("color", color);
		ini.addKey("power", power.x);
		ini.addKey("cutoff", cutoff.x);
		ini.addKey("use_colors", (int)userColors.x);
		ini.addKey("wavelengths", wavelengths);
		ini.addKey("mpirun_file", mpiCommand);
		ini.addKey("default_galaxy", galaxyFile );
		ini.addKey("default_galaxy_directory", galaxyDir);
		ini.addKey("convolve", convolve.x);
		ini.addKey("noise", noise);
		ini.addKey("renderlist", renderList);
		ini.addKey("preview", preview.x);
		ini.addKey("no_stars", noStars.x);
		ini.addKey("stars_spread", starsSpread.x);
		
		ini.Save(settingsFile);
	}
	
}

